﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region Motorcade

        public List<tb_Motorcade> GetAllMotorcade()
        {

            var query = (from obj in this.tb_Motorcades
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_Motorcade GetMotorcadeById(int id)
        {
            return this.tb_Motorcades.SingleOrDefault(tb_Motorcades => tb_Motorcades.Id == id);
        }

        public void CreateMotorcade(tb_Motorcade entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_Motorcades.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyMotorcade(tb_Motorcade entity)
        {
            tb_Motorcade instance = this.tb_Motorcades.SingleOrDefault(p => p.Id == entity.Id);
            instance.CarNo = entity.CarNo;
            instance.Description = entity.Description;
            instance.Driver = entity.Driver;
            instance.Loading = entity.Loading;
            instance.Name = entity.Name;
            instance.Status = entity.Status; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now; 

            this.SubmitChanges();
        }
        public void DeleteMotorcade(tb_Motorcade entity)
        {
            tb_Motorcade deleteEntity = tb_Motorcades.SingleOrDefault(p => p.Id == entity.Id);
            tb_Motorcades.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }
}
